package com.csu.bailan.common;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;

@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommonResponse<T> {
    private int states;
    private String message;
    private T data;
    //构造方法
    private CommonResponse(int states){
        this.states = states;
    }

    private CommonResponse(int states,String message){
        this.states = states;
        this.message = message;
    }

    private CommonResponse(int states, T data){
        this.states = states;
        this.data = data;
    }

        private CommonResponse(int states,String message,T data){
        this.states = states;
        this.message = message;
        this.data = data;
    }

    @JsonIgnore
    public boolean isSuccess(){
        return this.states == ResponseEnum.SUCCESS.getCode();
    }

    public static <T> CommonResponse<T> createForSuccess() {
        return new CommonResponse<T>(ResponseEnum.SUCCESS.getCode());
    }

    public static <T> CommonResponse<T> createForSuccessMessage(String message) {
        return new CommonResponse<>(ResponseEnum.SUCCESS.getCode(), message);
    }

    public static <T> CommonResponse<T> createForSuccess(T data) {
        return new CommonResponse<>(ResponseEnum.SUCCESS.getCode(), data);
    }

    public static <T> CommonResponse<T> createForSuccess(String message, T data) {
        return new CommonResponse<T>(ResponseEnum.SUCCESS.getCode(), message, data);
    }

    public static <T> CommonResponse<T> createForError() {
        return new CommonResponse<T>(ResponseEnum.ERROR.getCode(), ResponseEnum.ERROR.getMessage());
    }

    public static <T> CommonResponse<T> createForError(String message) {
        return new CommonResponse<T>(ResponseEnum.ERROR.getCode(), message);
    }


    public static <T> CommonResponse<T> createForError(int code, String message) {
        return new CommonResponse<T>(code, message);
    }


}
